﻿Imports Odyssee.WebControles
Imports OpenDelib.ServiceDeliberations

Public Class FicheRapport
    Inherits FicheDossierPage

    Protected ReadOnly Property TypeDossierAssemblee As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.TypeDossier, TypeDeliberation.Assemblee)
        End Get
    End Property
    Protected ReadOnly Property TypeDossierCommission As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.TypeDossier, TypeDeliberation.Commission)
        End Get
    End Property
    Protected ReadOnly Property ThesaurusNomenclature As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.ThesaurusNomenclature)
        End Get
    End Property
    Protected ReadOnly Property ThesaurusThemesGeneraux As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.ThesaurusThemesGeneraux)
        End Get
    End Property
    Protected ReadOnly Property ThesaurusOrdreJour As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.ThesaurusOrdreDuJour)
        End Get
    End Property
    Protected ReadOnly Property TypeLienInterDossierAssemblee As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.TypeLienInterDossierAssemblee)
        End Get
    End Property
    Protected ReadOnly Property TypeLienInterDossierRapport As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.TypeLienInterDossierRapport)
        End Get
    End Property
    Protected ReadOnly Property EtatDossierPlanifie As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.EtatDossierPlanifie)
        End Get
    End Property
    Protected ReadOnly Property TypeDocumentRapport As String
        Get
            Return Tools.GetInstance().Parametre(TypeParametre.TypeDocument, TypeDeliberation.Rapport)
        End Get
    End Property
    Protected ReadOnly Property CleDocumentRapport As Integer
        Get
            If IsNumeric(ViewState("cle_document_rapport")) Then Return CInt(ViewState("cle_document_rapport"))
            Return 0
        End Get
    End Property


    Public Overrides ReadOnly Property Titre As String
        Get
            Return "Fiche rapport"
        End Get
    End Property
    Protected Overrides ReadOnly Property TypeDelib As TypeDeliberation
        Get
            Return TypeDeliberation.Rapport
        End Get
    End Property
    Protected Overrides ReadOnly Property LibelleEntite As String
        Get
            Return "rapport"
        End Get
    End Property
    Protected Overrides ReadOnly Property LibelleFeminin As Boolean
        Get
            Return False
        End Get
    End Property
    Protected Overrides ReadOnly Property LibelleApostrophe As Boolean
        Get
            Return False
        End Get
    End Property
    Protected Overrides ReadOnly Property UtiliseDocuments As Boolean
        Get
            Return True
        End Get
    End Property
    Protected Overrides ReadOnly Property PopupPanel As JQPopupPanel
        Get
            Return Me.pnlRapport
        End Get
    End Property
    Protected Overrides ReadOnly Property BoutonActualiser As Button
        Get
            Return Me.btnActualiser
        End Get
    End Property
    Protected Overrides ReadOnly Property SeparateurActualiser As ToolBarSeparator
        Get
            Return Me.tbSep1
        End Get
    End Property
    Protected Overrides ReadOnly Property BoutonEnregistrer As Button
        Get
            Return Me.btnEnregister
        End Get
    End Property
    Protected Overrides ReadOnly Property SeparateurTraitements As ToolBarSeparator
        Get
            Return Me.tbSep2
        End Get
    End Property
    Protected Overrides ReadOnly Property BoutonTraitements As ToolBarTextImageMenuButton
        Get
            Return Me.btnTraitements
        End Get
    End Property


    Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            If Request.Form("__EVENTTARGET") = "btnAjouterNomenclature" Then
                AjouterDescripteur(ThesaurusNomenclature, Request.Form("ctl00$content$pnlRapport__hidden1"), Me.gvNomenclature, "nomenclatures")
            ElseIf Request.Form("__EVENTTARGET") = "btnAjouterTheme" Then
                AjouterDescripteur(ThesaurusThemesGeneraux, Request.Form("ctl00$content$pnlRapport__hidden1"), Me.gvTheme, "thèmes")
            ElseIf Request.Form("__EVENTTARGET") = "btnAjouterOrdreJour" Then
                AjouterDescripteur(ThesaurusOrdreJour, Request.Form("ctl00$content$pnlRapport__hidden1"), Me.gvOrdreJour, "ordres du jour")
            ElseIf Request.Form("__EVENTTARGET") = "btnAjouterPJ" Or
                   Request.Form("__EVENTTARGET") = "content_pnlRapport__button" Or
                   Request.Form("__EVENTTARGET") = "ctl00_content_pnlRapport__button" Then
                AjouterPieceJointe(CInt(Request.Form("ctl00$content$pnlRapport__hidden1")), Me.gvPiecesJointes)
            ElseIf Request.Form("__EVENTTARGET").Contains("btnModifierPJ") Then
                InitialiserPiecesJointes(Me.gvPiecesJointes)
            End If
        Else
            SetFocus(Me.txtObjet)
        End If
    End Sub

    Private Sub cmbSeance_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbSeance.SelectedIndexChanged
        Me.txtCodeSeance.Text = ""
        Me.txtDebutValSeance.Text = ""

        If Me.cmbSeance.SelectedValue <> "" Then
            Me.txtCodeSeance.Text = Me.cmbSeance.SelectedValue

            Using svc As New ServiceDossiers.DossiersClient
                Dim params As New ServiceDossiers.CriteresRechercheDossier
                params.Authentication = New ServiceDossiers.AuthenticationParameters
                params.Authentication.Token = Tools.GetInstance.getToken
                params.Code = Me.cmbSeance.SelectedValue

                Try
                    Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
                    If results Is Nothing OrElse Not results.OK Then
                        NotifyErreur("Impossible de charger les informations de la séance sélectionnée" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                    ElseIf results.Dossiers.Count > 0 AndAlso results.Dossiers(0).FinValidite <> #12:00:00 AM# Then
                        Me.txtDebutValSeance.Text = results.Dossiers(0).FinValidite.ToShortDateString
                    End If
                Catch ex As Exception
                    NotifyErreur(ex.Message)
                End Try
            End Using
        End If

        ChargerCommissions()
    End Sub

    Private Sub cmbCommission_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbCommission.SelectedIndexChanged
        Me.txtCodeCommission.Text = ""
        Me.txtNbMembresCommission.Text = ""

        If Me.cmbCommission.SelectedValue <> "" Then
            Me.txtCodeCommission.Text = Me.cmbCommission.SelectedValue
            Me.txtNbMembresCommission.Text = LireNombreMembresCommission(Me.cmbCommission.SelectedValue)
        End If
    End Sub

    Private Sub gvInstructeurs_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvInstructeurs.RowCommand
        Select Case e.CommandName.ToUpper
            Case "TRAITER"
                If Not IsNumeric(e.CommandArgument) Then Return
                TraiterDiffusion(CInt(e.CommandArgument))
        End Select
    End Sub

    Private Sub gvNomenclature_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvNomenclature.RowCommand
        Select Case e.CommandName.ToUpper
            Case "AJOUTER"

            Case "SUPPRIMER"
                Dim descripteur As String = ""
                Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
                descripteur = row.Cells(0).Text
                SupprimerDescripteur(Me.ThesaurusNomenclature, descripteur, Me.gvNomenclature, "nomenclatures")
        End Select
    End Sub

    Private Sub gvTheme_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvTheme.RowCommand
        Select Case e.CommandName.ToUpper
            Case "AJOUTER"

            Case "SUPPRIMER"
                Dim descripteur As String = ""
                Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
                descripteur = row.Cells(0).Text
                SupprimerDescripteur(Me.ThesaurusThemesGeneraux, descripteur, Me.gvTheme, "thèmes")
        End Select
    End Sub

    Private Sub gvOrdreJour_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvOrdreJour.RowCommand
        Select Case e.CommandName.ToUpper
            Case "AJOUTER"

            Case "SUPPRIMER"
                Dim descripteur As String = ""
                Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
                descripteur = row.Cells(0).Text
                SupprimerDescripteur(Me.ThesaurusOrdreJour, descripteur, Me.gvOrdreJour, "ordres du jour")
        End Select
    End Sub

    Private Sub gvPiecesJointes_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvPiecesJointes.RowCommand
        Select Case e.CommandName.ToUpper
            Case "AJOUTER"

            Case "SUPPRIMER"
                Dim cledocument As Integer = 0
                If IsNumeric(e.CommandArgument) Then cledocument = CInt(e.CommandArgument)

                If cledocument = 0 Then
                    NotifyErreur("Impossible de lire la clé du document à enlever.")
                    Return
                End If

                SupprimerPieceJointe(cledocument, Me.gvPiecesJointes)
        End Select
    End Sub


    Protected Overrides Sub InitialiserParametres()
        MyBase.InitialiserParametres()

        ' Chargement de la liste des types de rapport (zs code)
        Me.cmbTypeRapport.Items.Clear()
        Using svc As New ServiceParametre.ParametresClient
            Dim params As New ServiceParametre.ParametresDetailTypeEntite
            params.Authentication = New ServiceParametre.AuthenticationParameters
            params.Authentication.Token = Tools.GetInstance.getToken
            params.Type = Me.TypeDossier
            params.Entite = ServiceParametre.EnumsAcroTypeTableBase.Dossier

            Try
                Dim results As ServiceParametre.AffichageZoneSup = svc.DetailTypeEntite(params)
                If results Is Nothing OrElse Not results.OK Then
                    NotifyErreur("Impossible de charger la liste des types de rapport" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                Else
                    Me.cmbTypeRapport.Items.Add(New ListItem("Aucun type de rapport", ""))
                    For Each item As ServiceParametre.OIItem In results.ValeursCode
                        Me.cmbTypeRapport.Items.Add(New ListItem(item.Libelle, item.Code))
                    Next
                    Me.cmbTypeRapport.SelectedIndex = 0
                End If
            Catch ex As Exception
                NotifyErreur(ex.Message)
            End Try
        End Using

        ' Chargement de la liste des séances et des commissions
        Me.cmbSeance.Items.Clear()
        Me.cmbCommission.Items.Clear()

        Using svc As New ServiceDossiers.DossiersClient
            Dim params As New ServiceDossiers.CriteresRechercheDossier
            params.Authentication = New ServiceDossiers.AuthenticationParameters
            params.Authentication.Token = Tools.GetInstance.getToken

            ' Chargement de la liste des séances
            params.Type = Me.TypeDossierAssemblee
            params.Etat = Me.EtatDossierPlanifie

            Try
                Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
                If results Is Nothing OrElse Not results.OK Then
                    NotifyErreur("Impossible de charger la liste des séances" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                Else
                    Me.cmbSeance.Items.Add(New ListItem("Aucune séance", ""))
                    For Each dos As ServiceDossiers.Dossier In results.Dossiers
                        Me.cmbSeance.Items.Add(New ListItem(dos.Identificateur, dos.Code))
                    Next
                    Me.cmbSeance.SelectedIndex = 0
                    Me.txtCodeSeance.Text = ""
                    Me.txtDebutValSeance.Text = ""
                End If
            Catch ex As Exception
                NotifyErreur(ex.Message)
            End Try
        End Using
    End Sub

    Protected Overrides Sub InitialiserPage()
        MyBase.InitialiserPage()

        Select Case Me.ModeFiche

            Case Tools.ModeFiche.Creation
                Me.divInstructeurs.Visible = False
                Me.divNomenclature.Visible = False
                Me.divTheme.Visible = False
                Me.divOrdreJour.Visible = False
                Me.divPiecesJointes.Visible = False
                ChargerCommissions()

            Case Tools.ModeFiche.Modification
                ' Dossier
                Me.txtObjet.Text = Me.Entite.Identificateur
                Me.txtResume.Text = Me.Entite.Remarques
                Me.txtCode.Text = Me.Entite.Code
                Me.txtCleExt.Text = Me.Entite.CleExterne
                Me.cmbTypeRapport.SelectedValue = Me.Entite.ZoneSup.Code

                ' Séance et commission
                Me.txtDebutValSeance.Text = ""
                Me.txtCodeSeance.Text = ""
                Me.txtNbMembresCommission.Text = ""
                Me.txtCodeCommission.Text = ""

                Dim commission As ServiceDossiers.Dossier = Nothing
                Using svc As New ServiceDossiers.DossiersClient
                    Dim params As New ServiceDossiers.CriteresRechercheDossier
                    params.Authentication = New ServiceDossiers.AuthenticationParameters
                    params.Authentication.Token = Tools.GetInstance.getToken
                    params.DossierLie = Me.CleEntite

                    ' Séance
                    params.Type = Me.TypeDossierAssemblee
                    params.TypeRelationDossierLie = Me.TypeLienInterDossierAssemblee

                    Try
                        Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
                        If results Is Nothing OrElse Not results.OK Then
                            NotifyErreur("Impossible de charger la séance liée au rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                        ElseIf results.Dossiers.Count > 0 Then
                            Me.cmbSeance.SelectedValue = results.Dossiers(0).Code
                            Me.txtCodeSeance.Text = results.Dossiers(0).Code
                            If results.Dossiers(0).FinValidite <> #12:00:00 AM# Then Me.txtDebutValSeance.Text = results.Dossiers(0).FinValidite.ToShortDateString
                        End If
                    Catch ex As Exception
                        NotifyErreur(ex.Message)
                    End Try

                    ' Commission
                    params.Type = Me.TypeDossierCommission
                    params.TypeRelationDossierLie = Me.TypeLienInterDossierRapport

                    Try
                        Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
                        If results Is Nothing OrElse Not results.OK Then
                            NotifyErreur("Impossible de charger la commission liée au rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                        ElseIf results.Dossiers.Count > 0 Then
                            commission = results.Dossiers(0)
                        End If
                    Catch ex As Exception
                        NotifyErreur(ex.Message)
                    End Try
                End Using

                ChargerCommissions()
                If commission IsNot Nothing AndAlso Me.cmbCommission.Items.Count > 0 Then
                    Dim exists As Boolean = False
                    For Each item As ListItem In Me.cmbCommission.Items
                        If item.Value.ToUpper = commission.Code.ToUpper Then
                            exists = True
                            Exit For
                        End If
                    Next
                    If exists Then
                        Me.cmbCommission.SelectedValue = commission.Code
                        Me.txtCodeCommission.Text = commission.Code
                        Me.txtNbMembresCommission.Text = LireNombreMembresCommission(commission.Code)
                    Else
                        Me.cmbCommission.SelectedIndex = 0
                    End If
                End If



                ' Informations du document RAPPORT lié
                Dim cleDoc As Integer = 0

                Using svc As New ServiceDocuments.DocumentsClient
                    Dim params As New ServiceDocuments.CriteresRechercheDocument
                    params.Authentication = New ServiceDocuments.AuthenticationParameters
                    params.Authentication.Token = Tools.GetInstance.getToken
                    params.DossierLie = Me.CleEntite
                    params.Type = Me.TypeDocumentRapport

                    Dim results As ServiceDocuments.ResultatRechercheDocument = Nothing
                    Try
                        results = svc.Recherche(params)
                        If results Is Nothing OrElse Not results.OK Then
                            NotifyErreur("Impossible de charger le document RAPPORT du rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                        ElseIf results.Documents.Count > 0 Then
                            cleDoc = results.Documents(0).Cle
                            Me.txtSignature.Text = If(results.Documents(0).DocumentSigne, "Signé par " & results.Documents(0).UtilistateurSignature & " sur le poste " & results.Documents(0).PosteSignature & " le " & results.Documents(0).DateSignature.ToShortDateString & ".", "Non signé")
                            Me.txtVersion.Text = results.Documents(0).Version.ToString
                            Me.txtRedacteur.Text = results.Documents(0).NomRedacteur
                            Me.txtDomaineRedacteur.Text = results.Documents(0).DomaineRedacteur
                        End If
                    Catch ex As Exception
                        NotifyErreur(ex.Message)
                    End Try
                End Using

                ViewState("cle_document_rapport") = cleDoc

                ' Instructeurs
                ChargerDiffusions()

                ' Nomenclatures
                InitialiserDescripteurs(Me.ThesaurusNomenclature, Me.gvNomenclature, "nomenclatures")

                ' Thèmes
                InitialiserDescripteurs(Me.ThesaurusThemesGeneraux, Me.gvTheme, "thèmes")

                ' Ordres du jour
                InitialiserDescripteurs(Me.ThesaurusOrdreJour, Me.gvOrdreJour, "ordres du jour")

                ' Pièces jointes
                InitialiserPiecesJointes(Me.gvPiecesJointes)

        End Select
    End Sub

    Private Sub ChargerDiffusions()
        If Me.CleDocumentRapport > 0 Then
            Using svc As New ServiceDocuments.DocumentsClient
                Dim params As New ServiceDocuments.ParametresDiffusionsDocument
                params.Authentication = New ServiceDocuments.AuthenticationParameters
                params.Authentication.Token = Tools.GetInstance.getToken
                params.Cle = Me.CleDocumentRapport
                params.Utilisateur = Me.Master.Utilisateur

                Dim results As ServiceDocuments.ResultatListeDiffusionsDocument = Nothing
                Try
                    results = svc.ListeDiffusions(params)
                    If results Is Nothing OrElse Not results.OK Then
                        NotifyErreur("Impossible de charger les instructeurs du rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                    Else
                        Me.gvInstructeurs.DataSource = results.Diffusions
                        Me.gvInstructeurs.DataBind()
                    End If
                Catch ex As Exception
                    NotifyErreur(ex.Message)
                End Try
            End Using
        Else
            Me.gvInstructeurs.DataSource = New ServiceDocuments.Diffusion() {}
            Me.gvInstructeurs.DataBind()
        End If
    End Sub
    Private Sub TraiterDiffusion(cleDiffusion As Integer)
        If Me.CleDocumentRapport > 0 AndAlso cleDiffusion > 0 Then
            Using svc As New ServiceDocuments.DocumentsClient
                Dim params As New ServiceDocuments.ParametresDiffusionsDocument
                params.Authentication = New ServiceDocuments.AuthenticationParameters
                params.Authentication.Token = Tools.GetInstance.getToken
                params.Cle = Me.CleDocumentRapport
                params.CleDiffusion = cleDiffusion

                Dim results As ServiceDocuments.OperationResult = Nothing
                Try
                    results = svc.TraiterDiffusions(params)
                    If results Is Nothing OrElse Not results.OK Then
                        NotifyErreur("Impossible de traiter la diffusion n°" & cleDiffusion.ToString & " du rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                    Else
                        ChargerDiffusions()
                    End If
                Catch ex As Exception
                    NotifyErreur(ex.Message)
                End Try
            End Using

        End If
    End Sub

    Protected Overrides Function Renseigner() As Boolean
        If Not MyBase.Renseigner() Then Return False
        Entite.Identificateur = Me.txtObjet.Text
        Entite.Remarques = Me.txtResume.Text
        Entite.ZoneSup.Code = Me.cmbTypeRapport.SelectedValue
        Return True
    End Function

    Protected Overrides Function Creer() As Boolean
        If Not MyBase.Creer() Then Return False

        ' Ajout de la séance et de la commission si nécessaire
        Using svc As New ServiceDossiers.DossiersClient
            Dim pLien As New ServiceDossiers.ParametresLienDossierDossier
            pLien.Authentication = New ServiceDossiers.AuthenticationParameters
            pLien.Authentication.Token = Tools.GetInstance.getToken
            pLien.CodeDossier = CleEntite

            ' Séance
            If Me.cmbSeance.SelectedValue <> "" Then
                pLien.TypeRelation = Me.TypeLienInterDossierAssemblee
                pLien.CodeDossierLie = Me.cmbSeance.SelectedValue

                Try
                    Dim results As ServiceDossiers.OperationResult = svc.AjouterLienDossier(pLien)
                    If results Is Nothing OrElse Not results.OK Then
                        NotifyErreur("Impossible de créer le lien entre la séance '" & Me.cmbSeance.SelectedValue & "' et le rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                        Return False
                    End If
                Catch ex As Exception
                    NotifyErreur(ex.Message)
                    Return False
                End Try
            End If

            ' Séance
            If Me.cmbCommission.SelectedValue <> "" Then
                pLien.TypeRelation = Me.TypeLienInterDossierRapport
                pLien.CodeDossierLie = Me.cmbCommission.SelectedValue

                Try
                    Dim results As ServiceDossiers.OperationResult = svc.AjouterLienDossier(pLien)
                    If results Is Nothing OrElse Not results.OK Then
                        NotifyErreur("Impossible de créer le lien entre la commission '" & Me.cmbCommission.SelectedValue & "' et le rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                        Return False
                    End If
                Catch ex As Exception
                    NotifyErreur(ex.Message)
                    Return False
                End Try
            End If
        End Using

        Return True
    End Function

    Protected Overrides Function MettreAJour() As Boolean
        If Not MyBase.MettreAJour() Then Return False

        ' Mise à jour de la séance
        If Not MettreAJourLienDossier(Me.cmbSeance.SelectedValue, Me.TypeLienInterDossierAssemblee, Me.TypeDossierAssemblee) Then Return False

        ' Mise à jour de la commission
        If Not MettreAJourLienDossier(Me.cmbCommission.SelectedValue, Me.TypeLienInterDossierRapport, Me.TypeDossierCommission) Then Return False

        Return True
    End Function


    Private Function LireNombreMembresCommission(codeCommission As String) As String
        Using svc As New DeliberationsClient
            Dim params As New StringOperationParameters
            params.Authentication = New AuthenticationParameters
            params.Authentication.Token = Tools.GetInstance.getToken
            params.Value = codeCommission

            Try
                Dim results As IntegerOperationResult = svc.LireNombreMembresCommission(params)
                If results Is Nothing OrElse Not results.OK Then
                    NotifyErreur("Impossible de charger les informations de la commission sélectionnée" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                Else
                    Return results.Value.ToString + " membre(s)"
                End If
            Catch ex As Exception
                NotifyErreur(ex.Message)
            End Try
        End Using

        Return ""
    End Function

    Private Function MettreAJourLienDossier(codeLie As String, codeRelation As String, typeLie As String) As Boolean
        Using svc As New ServiceDossiers.DossiersClient
            Dim lien As String = ""

            ' Lecture du dossier actuel
            Dim pDossier As New ServiceDossiers.CriteresRechercheDossier
            pDossier.Authentication = New ServiceDossiers.AuthenticationParameters
            pDossier.Authentication.Token = Tools.GetInstance.getToken
            pDossier.DossierLie = Me.CleEntite
            pDossier.Type = typeLie
            pDossier.TypeRelationDossierLie = codeRelation

            Try
                Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(pDossier)
                If results Is Nothing OrElse Not results.OK Then
                    NotifyErreur("Impossible de charger l'élément lié au rapport '" & Me.CleEntite & "' (type de l'élément lié : " & typeLie & ")" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                    Return False
                ElseIf results.Dossiers.Count > 0 Then
                    lien = results.Dossiers(0).Code
                End If
            Catch ex As Exception
                NotifyErreur(ex.Message)
                Return False
            End Try

            ' Mise à jour du lien si nécessaire
            If lien.ToUpper <> codeLie.ToUpper Then
                Dim pLien As New ServiceDossiers.ParametresLienDossierDossier
                pLien.Authentication = New ServiceDossiers.AuthenticationParameters
                pLien.Authentication.Token = Tools.GetInstance.getToken
                pLien.CodeDossier = Me.CleEntite
                pLien.TypeRelation = codeRelation

                ' Suppression du lien actuel
                If lien <> "" Then
                    pLien.CodeDossierLie = lien

                    Try
                        Dim results As ServiceDossiers.OperationResult = svc.SupprimerLienDossier(pLien)
                        If results Is Nothing OrElse Not results.OK Then
                            NotifyErreur("Impossible de supprimer le lien entre l'élément '" & lien & "' et le rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                            Return False
                        End If
                    Catch ex As Exception
                        NotifyErreur(ex.Message)
                        Return False
                    End Try
                End If

                ' Ajout du nouveau lien
                If codeLie <> "" Then
                    pLien.CodeDossierLie = codeLie

                    Try
                        Dim results As ServiceDossiers.OperationResult = svc.AjouterLienDossier(pLien)
                        If results Is Nothing OrElse Not results.OK Then
                            NotifyErreur("Impossible de créer le lien entre l'élément '" & codeLie & "' et le rapport '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                            Return False
                        End If
                    Catch ex As Exception
                        NotifyErreur(ex.Message)
                        Return False
                    End Try
                End If
            End If
        End Using

        Return True
    End Function

    Private Sub ChargerCommissions()
        Me.cmbCommission.Items.Clear()
        Me.cmbCommission.Enabled = Me.cmbSeance.SelectedValue <> ""

        If Me.cmbSeance.SelectedValue = "" Then Return

        Using svc As New ServiceDossiers.DossiersClient
            Dim params As New ServiceDossiers.CriteresRechercheDossier
            params.Authentication = New ServiceDossiers.AuthenticationParameters
            params.Authentication.Token = Tools.GetInstance.getToken
            params.Type = Me.TypeDossierCommission
            params.Etat = ""
            params.DossierLie = Me.cmbSeance.SelectedValue
            params.TypeRelationDossierLie = Me.TypeLienInterDossierAssemblee

            Try
                Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
                If results Is Nothing OrElse Not results.OK Then
                    NotifyErreur("Impossible de charger la liste des commissions" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
                Else
                    Me.cmbCommission.Items.Add(New ListItem("Aucune commission", ""))
                    For Each dos As ServiceDossiers.Dossier In results.Dossiers
                        Me.cmbCommission.Items.Add(New ListItem(dos.Identificateur, dos.Code))
                    Next
                    Me.cmbCommission.SelectedIndex = 0
                    Me.txtCodeCommission.Text = ""
                    Me.txtNbMembresCommission.Text = ""
                End If
            Catch ex As Exception
                NotifyErreur(ex.Message)
            End Try
        End Using
    End Sub


    'Inherits OpenDelibPage

    'Public Const TYPE_DOSSIER As String = "RAPPOR"


    'Public ReadOnly Property ModeFiche As Tools.ModeFiche
    '    Get
    '        Return CType(ViewState("mode_fiche"), Tools.ModeFiche)
    '    End Get
    'End Property
    'Public ReadOnly Property CodeDossier As String
    '    Get
    '        Return CStr(ViewState("code_dossier"))
    '    End Get
    'End Property
    'Public ReadOnly Property Dossier As ServiceDossiers.Dossier
    '    Get
    '        Return CType(ViewState("dossier"), ServiceDossiers.Dossier)
    '    End Get
    'End Property
    ''Public ReadOnly Property ListeEtats As ServiceParametre.OIItemListResult
    ''    Get
    ''        Return CType(ViewState("liste_etats"), ServiceParametre.OIItemListResult)
    ''    End Get
    ''End Property
    'Public Property vsListeAssistants As ServiceAssistant.OIItemListResult
    '    Get
    '        Return CType(ViewState("liste_assistants"), ServiceAssistant.OIItemListResult)
    '    End Get
    '    Set(value As ServiceAssistant.OIItemListResult)
    '        ViewState("liste_assistants") = value
    '    End Set
    'End Property


    'Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    '    ' Permet de récupérer le fichier qui viens d'être drag & drop
    '    If Request.Files.Count = 1 Then
    '        'Copie du fichier déposé dans la dropzone sur le serveur
    '        Dim fichier As HttpPostedFile = Request.Files(0)

    '        Dim cheminFichier As String = Request.PhysicalApplicationPath & "Temp\" & Tools.GetInstance.getToken
    '        If Not IO.Directory.Exists(cheminFichier) Then IO.Directory.CreateDirectory(cheminFichier)

    '        cheminFichier &= "\" & System.IO.Path.GetFileName(fichier.FileName)

    '        Dim filestream As IO.FileStream = IO.File.Create(cheminFichier)
    '        Dim file As IO.Stream = fichier.InputStream
    '        file.Seek(0, IO.SeekOrigin.Begin)
    '        file.CopyTo(filestream)
    '        filestream.Dispose()

    '        ' Ouverture de la popup de création d'un document
    '        'Me.pnlRapport.ShowPopup("~/Commun/CreerDocument.aspx", "&selectionFichier=0&fichier=" & HttpUtility.UrlEncode(cheminFichier), , , , , , , , , , , , True)
    '    End If

    '    If IsPostBack Then
    '        If Request.Form("__EVENTTARGET") = "btnAjouterNomenclature" Then
    '            AjouterDescripteur("NOMENC", Request.Form("ctl00$content$pnlRapport__hidden1"), Me.gvNomenclature, "nomenclatures")
    '        ElseIf Request.Form("__EVENTTARGET") = "btnAjouterTheme" Then
    '            AjouterDescripteur("GENE", Request.Form("ctl00$content$pnlRapport__hidden1"), Me.gvTheme, "thèmes")
    '        ElseIf Request.Form("__EVENTTARGET") = "btnAjouterPJ" Or
    '               Request.Form("__EVENTTARGET") = "content_pnlRapport__button" Or
    '               Request.Form("__EVENTTARGET") = "ctl00_content_pnlRapport__button" Then
    '            AjouterPieceJointe(CInt(Request.Form("ctl00$content$pnlRapport__hidden1")))
    '        End If
    '    Else
    '        Master.Titre = "Fiche rapport"

    '        ' Lecture des paramètres
    '        ViewState("mode_fiche") = CType(Request.QueryString("modeFiche"), Tools.ModeFiche)
    '        ViewState("code_dossier") = ""

    '        ' Chargement du dossier depuis le service web
    '        InitializeFolder()

    '        ' Chargement des paramètres
    '        InitializeParameters()

    '        ' Chargement de la page
    '        InitializePage()

    '        SetFocus(Me.txtObjet)
    '    End If

    '    InitialiserBoutonsTraitement()
    'End Sub

    'Private Sub btnActualiser_Click(sender As Object, e As EventArgs) Handles btnActualiser.Click
    '    InitializeFolder()
    '    InitializePage()
    'End Sub

    'Private Sub btnEnregister_Click(sender As Object, e As EventArgs) Handles btnEnregister.Click
    '    Enregistrer()
    'End Sub

    'Private Sub btnImprimer_Click(sender As Object, e As EventArgs) Handles btnImprimer.Click

    'End Sub

    'Private Sub btnAssistant_Click(sender As Object, e As EventArgs)
    '    Dim codeAss As String

    '    codeAss = CType(sender, Odyssee.WebControles.ToolBarButton).CommandArgument

    '    Using svc As New ServiceAssistant.AssistantsClient
    '        Dim params As New ServiceAssistant.AssistantParameters
    '        params.Authentication = New ServiceAssistant.AuthenticationParameters
    '        params.Authentication.Token = Tools.GetInstance.getToken
    '        params.CleEntite = CodeDossier
    '        params.CodeAssistant = codeAss

    '        Try
    '            Dim results As ServiceAssistant.OperationResult
    '            results = svc.LancerAssistant(params)
    '            If results.OK Then
    '                NotifySuccess("Opération effectuée avec succès.")
    '                InitializeFolder()
    '                InitializePage()
    '            Else
    '                NotifyErreur(results.ErrorMessage)
    '            End If
    '        Catch ex As Exception
    '            NotifyErreur(ex.Message)
    '        End Try
    '    End Using
    'End Sub

    'Private Sub cmbSeance_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbSeance.SelectedIndexChanged
    '    Me.txtCodeSeance.Text = ""
    '    Me.txtDebutValSeance.Text = ""

    '    If Me.cmbSeance.SelectedValue <> "" Then
    '        Me.txtCodeSeance.Text = Me.cmbSeance.SelectedValue

    '        Using svc As New ServiceDossiers.DossiersClient
    '            Dim params As New ServiceDossiers.CriteresRechercheDossier
    '            params.Authentication = New ServiceDossiers.AuthenticationParameters
    '            params.Authentication.Token = Tools.GetInstance.getToken
    '            params.Code = Me.cmbSeance.SelectedValue

    '            Try
    '                Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
    '                If results Is Nothing OrElse Not results.OK Then
    '                    NotifyErreur("Impossible de charger les informations de la séance sélectionnée" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                ElseIf results.Dossiers.Count > 0 AndAlso results.Dossiers(0).FinValidite <> #12:00:00 AM# Then
    '                    Me.txtDebutValSeance.Text = results.Dossiers(0).FinValidite.ToShortDateString
    '                End If
    '            Catch ex As Exception
    '                NotifyErreur(ex.Message)
    '            End Try
    '        End Using
    '    End If
    'End Sub

    'Private Sub gvNomenclature_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvNomenclature.RowCommand
    '    Select Case e.CommandName.ToUpper
    '        Case "AJOUTER"

    '        Case "SUPPRIMER"
    '            Dim descripteur As String = ""
    '            Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
    '            descripteur = row.Cells(0).Text

    '            Using svc As New ServiceDescripteurs.DescripteursClient
    '                Dim params As New ServiceDescripteurs.ParametresLienDescripteur
    '                params.Authentication = New ServiceDescripteurs.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.Cle = CodeDossier
    '                params.Descripteur = descripteur
    '                params.Thesaurus = "NOMENC"
    '                params.TypeEntite = 1

    '                Try
    '                    Dim results As ServiceDescripteurs.OperationResult
    '                    results = svc.SupprimerLienDescripteur(params)
    '                    If results.OK Then
    '                        NotifySuccess("Suppression effectuée avec succès.")
    '                        InitializeDescripteurs("NOMENC", Me.gvNomenclature, "nomenclatures")
    '                    Else
    '                        NotifyErreur(results.ErrorMessage)
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                End Try
    '            End Using

    '    End Select
    'End Sub

    'Private Sub gvTheme_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvTheme.RowCommand
    '    Select Case e.CommandName.ToUpper
    '        Case "AJOUTER"

    '        Case "SUPPRIMER"
    '            Dim descripteur As String = ""
    '            Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
    '            descripteur = row.Cells(0).Text

    '            Using svc As New ServiceDescripteurs.DescripteursClient
    '                Dim params As New ServiceDescripteurs.ParametresLienDescripteur
    '                params.Authentication = New ServiceDescripteurs.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.Cle = CodeDossier
    '                params.Descripteur = descripteur
    '                params.Thesaurus = "GENE"
    '                params.TypeEntite = 1

    '                Try
    '                    Dim results As ServiceDescripteurs.OperationResult
    '                    results = svc.SupprimerLienDescripteur(params)
    '                    If results.OK Then
    '                        NotifySuccess("Suppression effectuée avec succès.")
    '                        InitializeDescripteurs("GENE", Me.gvTheme, "thèmes")
    '                    Else
    '                        NotifyErreur(results.ErrorMessage)
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                End Try
    '            End Using

    '    End Select
    'End Sub

    'Private Sub gvPiecesJointes_RowCommand(sender As Object, e As GridViewCommandEventArgs) Handles gvPiecesJointes.RowCommand
    '    Select Case e.CommandName.ToUpper
    '        Case "AJOUTER"

    '        Case "SUPPRIMER"
    '            Dim cledocument As Integer = 0
    '            Dim row As GridViewRow = CType(CType(e.CommandSource, Control).NamingContainer, GridViewRow)
    '            cledocument = If(IsNumeric(row.Cells(0).Text), CInt(row.Cells(0).Text), 0)

    '            If cledocument = 0 Then
    '                NotifyErreur("Impossible de lire la clé du document à enlever.")
    '                Return
    '            End If

    '            Using svc As New ServiceDossiers.DossiersClient
    '                Dim params As New ServiceDossiers.ParametresLienDossierDocument
    '                params.Authentication = New ServiceDossiers.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.CleDocument = cledocument
    '                params.CodeDossier = CodeDossier

    '                Try
    '                    Dim results As ServiceDossiers.OperationResult
    '                    results = svc.SupprimerLienDocument(params)
    '                    If results.OK Then
    '                        NotifySuccess("Suppression effectuée avec succès.")
    '                        InitializePiecesJointes()
    '                    Else
    '                        NotifyErreur(results.ErrorMessage)
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                End Try
    '            End Using

    '    End Select
    'End Sub


    'Private Sub InitializeFolder()
    '    If ModeFiche = Tools.ModeFiche.Modification Then
    '        ViewState("code_dossier") = Request.QueryString("codeDossier")

    '        If CodeDossier = "" Then
    '            ViewState("mode_fiche") = Tools.ModeFiche.Creation
    '        Else
    '            Using svc As New ServiceDossiers.DossiersClient
    '                Dim params As New ServiceDossiers.CriteresRechercheDossier
    '                params.Authentication = New ServiceDossiers.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.Code = CodeDossier

    '                Try
    '                    Dim results As ServiceDossiers.ResultatRechercheDossier
    '                    results = svc.Recherche(params)
    '                    If results.OK Then
    '                        If results.Dossiers.Count <= 0 Then
    '                            NotifyErreur("Le dossier ayant pour code '" & CodeDossier & "' est introuvable !")
    '                            ViewState("mode_fiche") = Tools.ModeFiche.Creation
    '                            ViewState("code_dossier") = ""
    '                        Else
    '                            ViewState("dossier") = results.Dossiers(0)
    '                        End If
    '                    Else
    '                        NotifyErreur(results.ErrorMessage)
    '                        ViewState("mode_fiche") = Tools.ModeFiche.Creation
    '                        ViewState("code_dossier") = ""
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                    ViewState("mode_fiche") = Tools.ModeFiche.Creation
    '                    ViewState("code_dossier") = ""
    '                End Try
    '            End Using
    '        End If
    '    End If
    'End Sub

    'Private Sub InitializeParameters()
    '    ' Chargement de la liste des états de dossier associés au type de dossier
    '    'Using svc As New ServiceParametre.ParametresClient
    '    '    Dim params As New ServiceParametre.ListeParametreParameters
    '    '    params.Authentication = New ServiceParametre.AuthenticationParameters
    '    '    params.Authentication.Token = Tools.GetInstance.getToken
    '    '    params.EntiteParametrage = 25
    '    '    params.Param1 = TYPE_DOSSIER

    '    '    Try
    '    '        ViewState("liste_etats") = svc.ListeParametre(params)
    '    '    Catch ex As Exception
    '    '        ViewState("liste_etats") = Nothing
    '    '        NotifyErreur(ex.Message)
    '    '    End Try
    '    'End Using

    '    ' Chargement de la liste des séances (dossiers ASSEMB)
    '    Me.cmbSeance.Items.Clear()
    '    Using svc As New ServiceDossiers.DossiersClient
    '        Dim params As New ServiceDossiers.CriteresRechercheDossier
    '        params.Authentication = New ServiceDossiers.AuthenticationParameters
    '        params.Authentication.Token = Tools.GetInstance.getToken
    '        params.Type = "ASSEMB"
    '        params.Etat = "PLANIF"

    '        Try
    '            Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
    '            If results Is Nothing OrElse Not results.OK Then
    '                NotifyErreur("Impossible de charger la liste des séances" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '            Else
    '                Me.cmbSeance.Items.Add(New ListItem("Aucune séance", ""))
    '                For Each dos As ServiceDossiers.Dossier In results.Dossiers
    '                    Me.cmbSeance.Items.Add(New ListItem(dos.Identificateur, dos.Code))
    '                Next
    '                Me.cmbSeance.SelectedIndex = 0
    '                Me.txtCodeSeance.Text = ""
    '                Me.txtDebutValSeance.Text = ""
    '            End If
    '        Catch ex As Exception
    '            NotifyErreur(ex.Message)
    '        End Try
    '    End Using


    '    If ModeFiche = Tools.ModeFiche.Modification Then
    '        ' Chargement de la liste des assistants associés au type de dossier
    '        Using svc As New ServiceAssistant.AssistantsClient
    '            Dim params As New ServiceAssistant.ListeDeclencheursAssistantParameters
    '            params.Authentication = New ServiceAssistant.AuthenticationParameters
    '            params.Authentication.Token = Tools.GetInstance.getToken
    '            params.TypeAssistant = 6
    '            params.TypeDeclencheur = 4
    '            params.TypeEvenement = 99
    '            params.CodeParametre = TYPE_DOSSIER
    '            params.CodeParametre2 = ""

    '            Try
    '                vsListeAssistants = svc.ListeAssistantsSelonParametreEtDeclencheur(params)
    '                If vsListeAssistants Is Nothing OrElse Not vsListeAssistants.OK Then
    '                    vsListeAssistants = Nothing
    '                    NotifyErreur("Impossible de charger les assistants associés au type de dossier '" & TYPE_DOSSIER & "'" & If(vsListeAssistants IsNot Nothing, " :" & ControlChars.NewLine & vsListeAssistants.ErrorMessage, "."))
    '                End If
    '            Catch ex As Exception
    '                vsListeAssistants = Nothing
    '                NotifyErreur(ex.Message)
    '            End Try
    '        End Using

    '    End If
    'End Sub

    'Private Sub InitialiserBoutonsTraitement()
    '    ' Ajout d'un bouton pour chaque assistant dans la barre d'outils
    '    Me.tbSep2.Visible = vsListeAssistants IsNot Nothing AndAlso vsListeAssistants.Liste.Count > 0
    '    Me.btnTraitements.Visible = vsListeAssistants IsNot Nothing AndAlso vsListeAssistants.Liste.Count > 0
    '    If vsListeAssistants IsNot Nothing AndAlso vsListeAssistants.Liste.Count > 0 Then
    '        For Each item As ServiceAssistant.OIItem In vsListeAssistants.Liste
    '            Dim btnAss As New Odyssee.WebControles.ToolBarButton()
    '            btnAss.CommandArgument = item.Code
    '            btnAss.ID = "btnAss" & item.Code
    '            btnAss.OnClientClick = "return confirm('Êtes-vous sûr de vouloir exécuter cette action ?');"
    '            btnAss.Text = item.Libelle
    '            AddHandler btnAss.Click, AddressOf btnAssistant_Click
    '            Me.btnTraitements.Add(btnAss)
    '        Next
    '    End If
    'End Sub

    'Private Sub InitializePage()
    '    Select Case Me.ModeFiche

    '        Case Tools.ModeFiche.Creation
    '            Me.btnActualiser.Visible = False
    '            Me.tbSep1.Visible = False
    '            Me.btnImprimer.Visible = False
    '            Me.tbSep2.Visible = False
    '            Me.btnTraitements.Visible = False

    '            Me.divInstructeurs.Visible = False
    '            Me.divNomenclature.Visible = False
    '            Me.divTheme.Visible = False
    '            Me.divPiecesJointes.Visible = False

    '        Case Tools.ModeFiche.Modification
    '            ' Dossier
    '            Me.txtObjet.Text = Me.Entite.Identificateur
    '            Me.txtResume.Text = Me.Entite.Remarques
    '            Me.txtCode.Text = Me.Entite.Code
    '            Me.txtCleExt.Text = Me.Entite.CleExterne

    '            ' Séance
    '            Me.txtDebutValSeance.Text = ""
    '            Me.txtCodeSeance.Text = ""
    '            Using svc As New ServiceDossiers.DossiersClient
    '                Dim params As New ServiceDossiers.CriteresRechercheDossier
    '                params.Authentication = New ServiceDossiers.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.DossierLie = Me.CleEntite
    '                params.Type = "ASSEMB"
    '                params.TypeRelationDossierLie = "ASSEMB"

    '                Try
    '                    Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(params)
    '                    If results Is Nothing OrElse Not results.OK Then
    '                        NotifyErreur("Impossible de charger la séance liée au dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                    ElseIf results.Dossiers.Count > 0 Then
    '                        Me.cmbSeance.SelectedValue = results.Dossiers(0).Code
    '                        Me.txtCodeSeance.Text = results.Dossiers(0).Code
    '                        If results.Dossiers(0).FinValidite <> #12:00:00 AM# Then Me.txtDebutValSeance.Text = results.Dossiers(0).FinValidite.ToShortDateString
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                End Try
    '            End Using

    '            ' Informations du document RAPPORT lié
    '            Dim cleDoc As Integer = 0

    '            Using svc As New ServiceDocuments.DocumentsClient
    '                Dim params As New ServiceDocuments.CriteresRechercheDocument
    '                params.Authentication = New ServiceDocuments.AuthenticationParameters
    '                params.Authentication.Token = Tools.GetInstance.getToken
    '                params.DossierLie = Me.CleEntite
    '                params.Type = "RAPPORT"

    '                Dim results As ServiceDocuments.ResultatRechercheDocument = Nothing
    '                Try
    '                    results = svc.Recherche(params)
    '                    If results Is Nothing OrElse Not results.OK Then
    '                        NotifyErreur("Impossible de charger le document RAPPORT du dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                    ElseIf results.Documents.Count > 0 Then
    '                        cleDoc = results.Documents(0).Cle
    '                        Me.txtSignature.Text = If(results.Documents(0).DocumentSigne, "Signé par " & results.Documents(0).UtilistateurSignature & " sur le poste " & results.Documents(0).PosteSignature & " le " & results.Documents(0).DateSignature.ToShortDateString & ".", "Non signé")
    '                        Me.txtVersion.Text = results.Documents(0).Version.ToString
    '                        Me.txtRedacteur.Text = results.Documents(0).NomRedacteur
    '                        Me.txtDomaineRedacteur.Text = results.Documents(0).DomaineRedacteur
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                End Try
    '            End Using

    '            ' Instructeurs
    '            If cleDoc > 0 Then
    '                Using svc As New ServiceDocuments.DocumentsClient
    '                    Dim params As New ServiceDocuments.ParametresDiffusionsDocument
    '                    params.Authentication = New ServiceDocuments.AuthenticationParameters
    '                    params.Authentication.Token = Tools.GetInstance.getToken
    '                    params.Cle = cleDoc

    '                    Dim results As ServiceDocuments.ResultatListeDiffusionsDocument = Nothing
    '                    Try
    '                        results = svc.ListeDiffusions(params)
    '                        If results Is Nothing OrElse Not results.OK Then
    '                            NotifyErreur("Impossible de charger les instructeurs du dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                        Else
    '                            Me.gvInstructeurs.DataSource = results.Diffusions
    '                            Me.gvInstructeurs.DataBind()
    '                        End If
    '                    Catch ex As Exception
    '                        NotifyErreur(ex.Message)
    '                    End Try
    '                End Using
    '            Else
    '                Me.gvInstructeurs.DataSource = New ServiceDocuments.Diffusion() {}
    '                Me.gvInstructeurs.DataBind()
    '            End If

    '            ' Nomenclatures
    '            InitializeDescripteurs("NOMENC", Me.gvNomenclature, "nomenclatures")

    '            ' Thèmes
    '            InitializeDescripteurs("GENE", Me.gvTheme, "thèmes")

    '            ' Pièces jointes
    '            InitializePiecesJointes()

    '    End Select
    'End Sub

    'Private Sub InitializeDescripteurs(thesaurus As String, gv As GridView, libelle As String)
    '    Using svc As New ServiceDescripteurs.DescripteursClient
    '        Dim params As New ServiceDescripteurs.ParametresListeDescripteursLies
    '        params.Authentication = New ServiceDescripteurs.AuthenticationParameters
    '        params.Authentication.Token = Tools.GetInstance.getToken
    '        params.Cle = Me.CleEntite
    '        params.Thesaurus = thesaurus
    '        params.TypeEntite = 1

    '        Dim results As ServiceDescripteurs.ResultatRechercheDescripteurs = Nothing
    '        Try
    '            results = svc.ListeDescripteursLies(params)
    '            If results Is Nothing OrElse Not results.OK Then
    '                NotifyErreur("Impossible de charger les " & libelle & " du dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '            Else
    '                gv.DataSource = results.Descripteurs
    '                gv.DataBind()
    '            End If
    '        Catch ex As Exception
    '            NotifyErreur(ex.Message)
    '        End Try
    '    End Using
    'End Sub

    'Private Sub InitializePiecesJointes()
    '    Using svc As New ServiceDocuments.DocumentsClient
    '        Dim params As New ServiceDocuments.CriteresRechercheDocument
    '        params.Authentication = New ServiceDocuments.AuthenticationParameters
    '        params.Authentication.Token = Tools.GetInstance.getToken
    '        params.DossierLie = Me.CleEntite

    '        Dim results As ServiceDocuments.ResultatRechercheDocument = Nothing
    '        Try
    '            results = svc.Recherche(params)
    '            If results Is Nothing OrElse Not results.OK Then
    '                NotifyErreur("Impossible de charger les pièces jointes du dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '            Else
    '                Me.gvPiecesJointes.DataSource = results.Documents
    '                Me.gvPiecesJointes.DataBind()
    '            End If
    '        Catch ex As Exception
    '            NotifyErreur(ex.Message)
    '        End Try
    '    End Using
    'End Sub

    'Private Sub AjouterDescripteur(thesaurus As String, descripteur As String, gv As GridView, libelle As String)
    '    Using svc As New ServiceDescripteurs.DescripteursClient
    '        Dim params As New ServiceDescripteurs.ParametresLienDescripteur
    '        params.Authentication = New ServiceDescripteurs.AuthenticationParameters
    '        params.Authentication.Token = Tools.GetInstance.getToken
    '        params.Cle = CodeDossier
    '        params.Descripteur = descripteur
    '        params.Thesaurus = thesaurus
    '        params.TypeEntite = 1

    '        Try
    '            Dim results As ServiceDescripteurs.OperationResult
    '            results = svc.AjouterLienDescripteur(params)
    '            If results.OK Then
    '                NotifySuccess("Ajout effectué avec succès.")
    '                InitializeDescripteurs(thesaurus, gv, libelle)
    '            Else
    '                NotifyErreur(results.ErrorMessage)
    '            End If
    '        Catch ex As Exception
    '            NotifyErreur(ex.Message)
    '        End Try
    '    End Using
    'End Sub

    'Private Sub AjouterPieceJointe(cleDocument As Integer)
    '    Using svc As New ServiceDossiers.DossiersClient
    '        Dim params As New ServiceDossiers.ParametresLienDossierDocument
    '        params.Authentication = New ServiceDossiers.AuthenticationParameters
    '        params.Authentication.Token = Tools.GetInstance.getToken
    '        params.CleDocument = cleDocument
    '        params.CodeDossier = CodeDossier

    '        Try
    '            Dim results As ServiceDossiers.OperationResult
    '            results = svc.AjouterLienDocument(params)
    '            If results.OK Then
    '                NotifySuccess("Ajout effectué avec succès.")
    '                InitializePiecesJointes()
    '            Else
    '                NotifyErreur(results.ErrorMessage)
    '            End If
    '        Catch ex As Exception
    '            NotifyErreur(ex.Message)
    '        End Try
    '    End Using
    'End Sub

    'Private Sub Enregistrer()
    '    If Me.ModeFiche = Tools.ModeFiche.Creation Then
    '        Dim codeDossier As String = ""

    '        Dim dossier As New ServiceAssistant.Dossier
    '        dossier.Identificateur = Me.txtObjet.Text
    '        dossier.Remarques = Me.txtResume.Text
    '        dossier.ZoneSup = New ServiceAssistant.ZoneSup()
    '        dossier.DossierClos = False
    '        dossier.Type = TYPE_DOSSIER

    '        Using svc As New ServiceAssistant.AssistantsClient
    '            Dim params As New ServiceAssistant.AssistantParameters
    '            params.Authentication = New ServiceAssistant.AuthenticationParameters
    '            params.Authentication.Token = Tools.GetInstance.getToken
    '            params.CodeAssistant = "CRTPRPJ"
    '            params.DefinitionDossier = dossier

    '            Try
    '                Dim results As ServiceAssistant.ExecutionAssistantResult = svc.LancerAssistant(params)
    '                If results Is Nothing OrElse Not results.OK Then
    '                    NotifyErreur("Impossible de créer le dossier" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                    Return
    '                Else
    '                    codeDossier = CStr(results.CleEntite)
    '                End If
    '            Catch ex As Exception
    '                NotifyErreur(ex.Message)
    '                Return
    '            End Try
    '        End Using

    '        Using svc As New ServiceDossiers.DossiersClient
    '            ' Ajout de la séance si nécessaire
    '            If Me.cmbSeance.SelectedValue <> "" Then
    '                Dim pLienSeance As New ServiceDossiers.ParametresLienDossierDossier
    '                pLienSeance.Authentication = New ServiceDossiers.AuthenticationParameters
    '                pLienSeance.Authentication.Token = Tools.GetInstance.getToken
    '                pLienSeance.CodeDossier = codeDossier
    '                pLienSeance.TypeRelation = "ASSEMB"
    '                pLienSeance.CodeDossierLie = Me.cmbSeance.SelectedValue

    '                Try
    '                    Dim results As ServiceDossiers.OperationResult = svc.AjouterLienDossier(pLienSeance)
    '                    If results Is Nothing OrElse Not results.OK Then
    '                        NotifyErreur("Impossible de créer le lien entre la séance '" & Me.cmbSeance.SelectedValue & "' et le dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                        Return
    '                    End If
    '                Catch ex As Exception
    '                    NotifyErreur(ex.Message)
    '                    Return
    '                End Try
    '            End If
    '        End Using

    '        ' Rechargement complet de la page
    '        Response.Redirect("~/Rapport/FicheRapport.aspx?modeFiche=1&codeDossier=" & codeDossier)

    '    ElseIf Me.ModeFiche = Tools.ModeFiche.Modification Then
    '        Dim dossier As New ServiceDossiers.Dossier

    '        dossier.Code = CodeDossier
    '        dossier.Identificateur = Me.txtObjet.Text
    '        dossier.Remarques = Me.txtResume.Text
    '        dossier.ZoneSup = New ServiceDossiers.ZoneSup()

    '        ' Mise à jour
    '        Using svc As New ServiceDossiers.DossiersClient
    '            Dim seance As String = ""

    '            ' Lecture de la séance actuelle
    '            Dim pSeance As New ServiceDossiers.CriteresRechercheDossier
    '            pSeance.Authentication = New ServiceDossiers.AuthenticationParameters
    '            pSeance.Authentication.Token = Tools.GetInstance.getToken
    '            pSeance.DossierLie = Me.CleEntite
    '            pSeance.Type = "ASSEMB"
    '            pSeance.TypeRelationDossierLie = "ASSEMB"

    '            Try
    '                Dim results As ServiceDossiers.ResultatRechercheDossier = svc.Recherche(pSeance)
    '                If results Is Nothing OrElse Not results.OK Then
    '                    NotifyErreur("Impossible de charger la séance liée au dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                    Return
    '                ElseIf results.Dossiers.Count > 0 Then
    '                    seance = results.Dossiers(0).Code
    '                End If
    '            Catch ex As Exception
    '                NotifyErreur(ex.Message)
    '                Return
    '            End Try

    '            ' Mise à jour de la séance si nécessaire
    '            If seance.ToUpper <> Me.cmbSeance.SelectedValue.ToUpper Then
    '                Dim pLienSeance As New ServiceDossiers.ParametresLienDossierDossier
    '                pLienSeance.Authentication = New ServiceDossiers.AuthenticationParameters
    '                pLienSeance.Authentication.Token = Tools.GetInstance.getToken
    '                pLienSeance.CodeDossier = Me.CleEntite
    '                pLienSeance.TypeRelation = "ASSEMB"

    '                ' Suppression de la séance actuelle
    '                If seance <> "" Then
    '                    pLienSeance.CodeDossierLie = seance

    '                    Try
    '                        Dim results As ServiceDossiers.OperationResult = svc.SupprimerLienDossier(pLienSeance)
    '                        If results Is Nothing OrElse Not results.OK Then
    '                            NotifyErreur("Impossible de supprimer le lien entre la séance '" & seance & "' et le dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                            Return
    '                        End If
    '                    Catch ex As Exception
    '                        NotifyErreur(ex.Message)
    '                        Return
    '                    End Try
    '                End If

    '                ' Ajout de la nouvelle séance
    '                If Me.cmbSeance.SelectedValue <> "" Then
    '                    pLienSeance.CodeDossierLie = Me.cmbSeance.SelectedValue

    '                    Try
    '                        Dim results As ServiceDossiers.OperationResult = svc.AjouterLienDossier(pLienSeance)
    '                        If results Is Nothing OrElse Not results.OK Then
    '                            NotifyErreur("Impossible de créer le lien entre la séance '" & Me.cmbSeance.SelectedValue & "' et le dossier '" & Me.CleEntite & "'" & If(results Is Nothing, ".", " :" & ControlChars.NewLine & results.ErrorMessage))
    '                            Return
    '                        End If
    '                    Catch ex As Exception
    '                        NotifyErreur(ex.Message)
    '                        Return
    '                    End Try
    '                End If
    '            End If

    '            ' Mise à jour du dossier
    '            Dim params As New ServiceDossiers.ParametresCreationDossier
    '            params.Authentication = New ServiceDossiers.AuthenticationParameters
    '            params.Authentication.Token = Tools.GetInstance.getToken
    '            params.Dossier = Dossier

    '            Dim result As New ServiceDossiers.OperationResult
    '            Try
    '                result = svc.MiseAJour(params)
    '                If result.OK Then
    '                    NotifySuccess("Dossier mis à jour avec succès.")
    '                Else
    '                    NotifyErreur("Echec de la mise à jour du dossier : " & result.ErrorMessage)
    '                    Return
    '                End If
    '            Catch ex As Exception
    '                NotifyErreur(ex.Message)
    '                Return
    '            End Try
    '        End Using
    '    End If
    'End Sub

    'Private Sub pnlRapport_ValueReturned(sender As Object, e As Odyssee.WebControles.JQPopupPanel.ValueReturnedEventArgs) Handles pnlRapport.ValueReturned
    '    Dim a As String = e.Value
    'End Sub


End Class